var nowPage = 0;
var totalPage = 4;
$(document).ready(function(){
	var width = window.innerWidth;
	var height = window.innerHeight;
	$(".content").width(width).height(height * 4);
	$(".page").width(width).height(height);
	
	//滑动监听
	$(".content").swipe({
		swipe:function(event,direction,duration,distance,fingerCount){
			if(direction == "up" && nowPage < totalPage - 1){
				nowPage+=1;
			}
			if(direction == "down" && nowPage > 0){
				nowPage-=1;
			}
			//滑动操作
			$(".content").animate({"top":-nowPage * height+"px"},{duration:2000,complete:startAnimate});
		}
	});	
	
	$(".page1_door").fadeIn(2000,startPage1Ani());
});

//第一页初始化动画
function startPage1Ani(){
	$(".page1_title_p1,.page1_title_p2").animate({"left":"30%"},{duration:2000});
	$(".page1_title_p3,.page1_title_p4").animate({"left":"50%"},{duration:2000});
	$(".page1 .line1").animate({"width":"60%","left":"20%"},{duration:2000});
	$(".page1 .line2").animate({"height":"50%","top":"10%"},{duration:2000});
}

function startAnimate(){
	//第二页初始化动画
	if(nowPage == 1){
		$(".page2_bg_left").fadeIn(1000,function(){
			$(".page2_bg_right").fadeIn(1000,function(){
				$(".page2_bg_bottom").animate({"width":"100%","left":"0px"},{duration:1000,complete:function(){
					$(".page2_title_p1").fadeIn(1000);
					$(".page2_title_p2").fadeIn(1000);
					$(".page2_title_p3").fadeIn(1000);
					$(".page2_title_p4").fadeIn(1000,function(){
						$(".page2_ticket").css("transform","rotate(360deg)")
						.css("left","15%");
						$(".page2_sleep").css("transform","rotate(-360deg)")
						.css("right","25%");
					});
				}});
			});
		});
	} else if(nowPage == 2) { //第三页
		page3();
	} else {
		page4();
	}
}
function page3() {
	$(".page3_modu3").fadeIn(2000, function() {
		$(".page3_modu3").animate({
			"width": "80%",
			"height": "35%",
			"left": "10%",
			"top": "35%"
		}, {
			duration: 1000,
			complete: function() {
				$(".page3_bg_left").fadeIn(1000,function(){
					$(".page3_bg_right").fadeIn(1000,function(){
						$(".page3_bg_bottom").animate({"width":"100%","left":"0px"},{duration:1000,complete:function(){
							
						}});
					});
				});
				
				$(".page3_modu2").css("transform", "rotate(375deg)").css("left", "15%").css("opacity", "1");

				$(".page3_modu4").css("transform", "rotate(350deg)").css("left", "15%").css("opacity", "1");
			}
		});
	});
}

function page4() {
	$(".page4_bg_left").fadeIn(1000,function(){
		$(".page4_bg_right").fadeIn(1000,function(){
			$(".page4_bg_bottom").animate({"width":"100%","left":"0px"},{duration:1000,complete:function(){
				
			}});
		});
	});
	
	
	$(".page4_1").fadeIn(2000, function() {
		$(".page4_2").fadeIn(2000, function() {
			$(".page4_3").fadeIn(2000, function() {
				$(".page4_4").fadeIn(2000, function() {
					$(".p4").css("bottom","5%");
				});
			});
		});
	});
}